package com.bdth.service.impl;

import com.bdth.mapper.CommandCardMapper;
import com.bdth.mapper.DeviceMapper;
import com.bdth.model.CommandCard;
import com.bdth.model.User;
import com.bdth.service.IDeviceBindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DeviceBindServiceImpl extends BaseServiceImpl<CommandCard> implements IDeviceBindService {

	@Autowired
	private CommandCardMapper mapper;

	@Autowired
	private DeviceMapper deviceMapper;

	@Override
	public List<Map> queryMapDataByMapList(Map map) throws Exception {
		return mapper.queryMapDataByMapList(map);
	}

	@Override
	public CommandCard getCommandCardBySimNo(String simNo) {
		return mapper.getCommandCardBySimNo(simNo);
	}

	@Override
	public void add(User user, String[] simNos, String parentSim) throws Exception {

		//查找CommandCard中数据
		CommandCard commandCardSearch = getCommandCardBySimNo(parentSim);
		if (commandCardSearch == null) {
			CommandCard commandCard = new CommandCard();
			commandCard.setSimNo(parentSim);
			commandCard.setIsCommand(1);
			commandCard.setParentSim("0");
			super.add(commandCard);
		}
		for (String simNo : simNos) {
			CommandCard commandCard1 = new CommandCard();
			commandCard1.setSimNo(simNo);
			commandCard1.setIsCommand(0);
			commandCard1.setParentSim(parentSim);
			super.add(commandCard1);
		}
	}

	@Override
	public List<Map> queryBindDataByMapList(Map map) throws Exception {
		return mapper.queryBindDataByMapList(map);
	}

	public List<Map> queryUnBindDeviceTree(Map map) throws Exception {
		return deviceMapper.queryUnBindDeviceTree(map);
	}
}
